package com.kai.steering.common.vo;

import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @ Author     ：LiuKai.
 * @ Date       ：Created in 10:52 2022-2-22
 * @ Description：分页模型
 * @ Modified By：
 * @Version:
 */
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Page<T>  implements Serializable {

    private static final long serialVersionUID = 1L;

    /*** 总记录数  */
    @Getter
    @Setter
    private Integer totalCount = 0;

    /*** 每页记录条数，默认 10  */
    @Getter
    @Setter
    private Integer pageSize = 10;

    /*** 当前页   */
    @Getter
    @Setter
    private Integer currPage = 1;

    /*** 查询数据列表   */
    @Getter
    @Setter
    private List<T> list = Collections.emptyList();

    /**
     * 当前分页总页数
     */
    public int getTotalPage() {
        if (getPageSize() == 0) {
            return 0;
        }
        int totalPage = getTotalCount() / getPageSize();
        if (getTotalCount() % getPageSize() != 0) {
            totalPage++;
        }
        return totalPage;
    }

    /**
     * 分页构造函数
     * @param currPage 当前页
     * @param pageSize    每页显示条数
     */
    public Page(int currPage, int pageSize) {
        if (currPage > 1) {
            this.currPage = currPage;
        }
        this.pageSize = pageSize;
    }

}

